<template>
  <el-dropdown trigger="click">
    <el-avatar :size="30" :src="$store.state.Admin.userData.avatarUrl" />
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item v-for="(item,index) in userList" :key="index" @click="userChange(index,item)">
          <el-icon>
            <component :is="item.icon"></component>
          </el-icon>{{item.name}}
        </el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script>
import { UserFilled, Lock, Right } from '@element-plus/icons-vue';
import { get } from "@/utils/http";
export default {
  components: {
    UserFilled, Lock, Right
  },
  data() {
    return {
      userList: [
        { name: '个人信息', icon: 'UserFilled', path: '/index/userinfo' },
        { name: '修改密码', icon: 'Lock', path: "/index/changepwd" },
        { name: '退出登录', icon: 'Right' }
      ]
    }
  },
  created() {
    // 用户信息
    get({ _gp: 'admin',_mt: 'info'}).then(res => {
      if (200 == res.errno) {
        this.$store.state.Admin.userData = res.data  //储存到vuex
      }
    })
  },
  methods: {
    // 用户操作
    userChange(ind, item) {
      if (2 == ind) {  //退出登录
        this.$store.dispatch('exitLogin', this.$router)
      } else {
        this.$router.push(item.path)
      }
    }
  }
}
</script>

